import 'dart:convert';
import 'package:cloud_medicine/components/util.dart';
import 'package:dio/dio.dart';
import 'HttpUtil.dart';

Future getShopList_api(String url) async {
  //药店列表接口
  Response res = await HttpUtil.request(
    url,
    method: HttpUtil.GET,
  );
  return jsonDecode(res.data); //后端传给前端的json数据
}

Future getMedicineList_api(String url, Map<String, dynamic> data) async {
  //药品列表接口
  Response res = await HttpUtil.get(url, parameters: data);
  return jsonDecode(res.data);
}

Future getShopInfo_api(String url, Map<String, dynamic> data) async {
  //药店信息列表接口
  String token = await getToken();
  Response res = await HttpUtil.get(
    // get要传参时使用这个方法
    url,
    parameters: data,
    headers: {'Authorization': token},
  );
  return jsonDecode(res.data);
}

Future getOrderList_api(String url, Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.request(
    url,
    method: HttpUtil.POST,
    parameters: data,
    headers: {'Authorization': token},
  );
  return jsonDecode(res.data);
}

Future getMedicineInfo_api(String url, Map<String, dynamic> data) async {
  //药品信息接口
  Response res = await HttpUtil.get(url, parameters: data);
  return jsonDecode(res.data);
}

Future getCollectList_api(String url) async {
  String token = await getToken();
  Response res = await HttpUtil.request(
    url,
    method: HttpUtil.GET,
    headers: {'Authorization': token},
  );
  return jsonDecode(res.data);
}

Future collectOrCancel_api(String url, Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.request(url,
      method: HttpUtil.POST,
      headers: {'Authorization': token},
      parameters: data);
  return jsonDecode(res.data);
}

Future createOrder_api(String url, Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.request(url,
      method: HttpUtil.POST,
      headers: {'Authorization': token},
      parameters: data);
  return jsonDecode(res.data);
}

Future getOrderInfo_api(String url, Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.get(url,
      headers: {'Authorization': token}, parameters: data);
  return jsonDecode(res.data);
}

Future deleteShop_api(String url, Map<String, dynamic> data) async {
  Response res =
      await HttpUtil.request(url, method: HttpUtil.POST, parameters: data);
  return jsonDecode(res.data);
}

Future addShopGrade_api(String url, Map<String, dynamic> data) async {
  Response res =
      await HttpUtil.request(url, method: HttpUtil.POST, parameters: data);
  return jsonDecode(res.data);
}

Future editOrderStatus_api(String url, Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.request(url,
      method: HttpUtil.POST,
      headers: {'Authorization': token},
      parameters: data);
  return jsonDecode(res.data);
}

Future deleteMedicine_api(String url, Map<String, dynamic> data) async {
  Response res =
      await HttpUtil.request(url, method: HttpUtil.POST, parameters: data);
  return jsonDecode(res.data);
}

Future addMedicine_api(String url, Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.request(url,
      method: HttpUtil.POST,
      headers: {'Authorization': token},
      parameters: data);
  return jsonDecode(res.data);
}

Future editMedicine_api(String url, Map<String, dynamic> data) async {
  Response res =
      await HttpUtil.request(url, method: HttpUtil.POST, parameters: data);
  return jsonDecode(res.data);
}

Future editShopInfo_api(String url, Map<String, dynamic> data) async {
  Response res =
      await HttpUtil.request(url, method: HttpUtil.POST, parameters: data);
  return jsonDecode(res.data);
}

Future reportError_api(String url, Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.request(url,
      method: HttpUtil.POST,
      headers: {'Authorization': token},
      parameters: data);
  return jsonDecode(res.data);
}

Future addChat_api(String url, Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.request(url,
      method: HttpUtil.POST,
      headers: {'Authorization': token},
      parameters: data);
  return jsonDecode(res.data);
}
